package com.pets.service.Impl;

import com.pets.dao.KnowledgeDisMapper;
import com.pets.dao.KnowledgeMapper;
import com.pets.enums.YesNoEnum;
import com.pets.service.AdminKnowledgeService;
import com.pets.util.Result;
import com.pets.vo.KnowledgeDisListVO;
import com.pets.vo.KnowledgeListVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class AdminKnowledgeServiceImpl implements AdminKnowledgeService {

    @Resource
    private KnowledgeMapper knowledgeMapper;

    @Resource
    private KnowledgeDisMapper knowledgeDisMapper;

    @Override
    public List<KnowledgeListVO> getKnowledgeList() {
        return knowledgeMapper.getKnowledgeList();
    }

    @Override
    public Result deleteKnowledge(int kId) {
        Result  result = new Result();
        int i = knowledgeMapper.deleteByPrimaryKey(kId);
        if(i>0){
            result.setMsg("删除成功");
            result.setCode(YesNoEnum.YES.getCode());
        }else {
            result.setMsg("删除失败");
            result.setCode(YesNoEnum.NO.getCode());
        }
        return result;
    }

    @Override
    public List<KnowledgeDisListVO> getKnowledgeDisList() {
        return knowledgeDisMapper.getKnowledgeDisList();
    }

    @Override
    public Result deleteKnowledgeDis(int kdId) {
        Result  result = new Result();
        int i = knowledgeDisMapper.deleteByPrimaryKey(kdId);
        if(i>0){
            result.setMsg("删除成功");
            result.setCode(YesNoEnum.YES.getCode());
        }else {
            result.setMsg("删除失败");
            result.setCode(YesNoEnum.NO.getCode());
        }
        return result;
    }
}
